﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace DataAchive.Helper
{
    public class DataShowConnectorHelper
    {
        public static List<KeyValuePair<string, string>> dataShowSiteAndConnections = new List<KeyValuePair<string, string>>();
        public static List<KeyValuePair<string, string>> connectionMachines = new List<KeyValuePair<string, string>>();

        public static string CurrentSiteAddress { get; set; }

        public static void GetXmlSetting()
        {
            try
            {
                if (dataShowSiteAndConnections.Count == 0)
                {
                    XmlNode dbNodes = Setting.GetXmlNode("setting/DataShowDB");
                    if (dbNodes != null)
                    {
                        for (int i = 0; i < dbNodes.ChildNodes.Count; i++)
                        {
                            if (dbNodes.ChildNodes[i].NodeType == XmlNodeType.Element)
                            {
                                var childNodes = dbNodes.ChildNodes[i].ChildNodes;
                                if (childNodes != null)
                                {
                                    if (childNodes.Count < 3)
                                    {
                                        SoftCommon.Log.Write("childnodes less 3.");

                                    }
                                    var constr = childNodes[0].InnerText;
                                    var sitename = childNodes[1].InnerText;
                                    var machinds = childNodes[2].InnerText;
                                    dataShowSiteAndConnections.Add(new KeyValuePair<string, string>(sitename, constr));
                                    connectionMachines.Add(new KeyValuePair<string, string>(sitename, machinds));
                                }

                            }

                        }

                    }

                }
            }
            catch (Exception e)
            {

                SoftCommon.Log.Write(e);
            }



        }


    }
}
